package light.head.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Formula;


/**
 * 首页广告
 */
@Entity
@Table
public class IndexAdvertising implements Serializable{
	
	private static final long serialVersionUID = 8569562341210194831L;
	private Integer code; 						// 流水号
	private String title; 						// 广告标题
	private String content; 					// 详细内容
	private Date pt; 							// 发布时间
	private String pm; 							// 发布人
	private Integer cu; 						// 创建人
	private Date ct; 							// 创建时间
	private String cn; 							// 创建人真实姓名
	private Integer ac; 						// 附件数量
	private Boolean deleted = false; 			// 是否删除
	private Integer sort; 						// 排序

	private List<IndexAdvertisingAnnex> list; 	// 广告附件
	private String coverPath;					// 封面

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column
	public Integer getCode() {
		return code;
	}

	@Column(length = 200)
	public String getTitle() {
		return title;
	}

	@Column(length = 10000)
	public String getContent() {
		return content;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column
	public Date getPt() {
		return pt;
	}

	@Column
	public String getPm() {
		return pm;
	}

	@Column
	public Integer getCu() {
		return cu;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(updatable = false, nullable = false)
	public Date getCt() {
		return ct;
	}

	@Column
	public Boolean getDeleted() {
		return deleted;
	}

	@Formula("(SELECT u.realName FROM UserInfo u WHERE u.code = cu)")
	public String getCn() {
		return cn;
	}

	@Formula("(SELECT COUNT(*) FROM IndexAdvertisingAnnex iaa WHERE iaa.iac = code)")
	public Integer getAc() {
		return ac;
	}

	@Transient
	public List<IndexAdvertisingAnnex> getList() {
		return list;
	}

	@Transient
	public String getCoverPath() {
		return coverPath;
	}

	@Column
	public Integer getSort() {
		return sort;
	}

	
	
	
	public void setCn(String cn) {
		this.cn = cn;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public void setPt(Date pt) {
		this.pt = pt;
	}

	public void setPm(String pm) {
		this.pm = pm;
	}

	public void setCu(Integer cu) {
		this.cu = cu;
	}

	public void setCt(Date ct) {
		this.ct = ct;
	}

	public void setAc(Integer ac) {
		this.ac = ac;
	}

	public void setList(List<IndexAdvertisingAnnex> list) {
		this.list = list;
	}

	public void setDeleted(Boolean deleted) {
		this.deleted = deleted;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	public void setCoverPath(String coverPath) {
		this.coverPath = coverPath;
	}

	public void addList(IndexAdvertisingAnnex iaa) {
		if (this.list == null) {
			this.list = new ArrayList<IndexAdvertisingAnnex>();
		}
		this.list.add(iaa);
	}

}
